//
//  XJWelcomeViewController.swift
//  XJWeiBO
//
//  Created by 452608533 on 16/7/22.
//  Copyright © 2016年 452608533. All rights reserved.
//

import UIKit

class XJWelcomeViewController: UIViewController {
    
    override func loadView() {
        view = bgImageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        self.headImagView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.4, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                UIView.animateWithDuration(0.5, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootViewControllerNoti, object: "welcome")
                })
        }
    }
    
    func setupUI() {
        //添加控件
        view.addSubview(headImagView)
        view.addSubview(messageLabel)
        //设置约束
        headImagView.snp_makeConstraints { (make) -> Void in
            make.height.width.equalTo(90)
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImagView.snp_bottom).offset(16)
            make.centerX.equalTo(view)
        }
    }
    
    private lazy var bgImageView: UIImageView = {
        let bg = UIImageView()
        bg.image = UIImage(named: "ad_background")
        return bg
    }()
    
    private lazy var headImagView:UIImageView = {
        
        let img = UIImageView()
        img.xj_setImage(XJUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeHolderImgName: "avatar_default_big")
        
        img.layer.borderColor =  UIColor.orangeColor().CGColor
        img.layer.borderWidth = 2
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        return img
    }()
    private lazy var messageLabel: UILabel = {
       
        let lab = UILabel(textColor: UIColor.darkGrayColor(), textFont: 18)
        lab.text = "欢迎回来"
        lab.textAlignment = .Center
        lab.alpha = 0
        
        return lab
    }()
}
